import java.util.*;

public class TestThread {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		BlockingQueue queue = new BlockingQueue();
		queue.putItem("ddd");
		System.out.println(queue.getItem());
		System.out.println(queue.getItem());
		System.out.println(queue.getItem());
	}
}

class BlockingQueue {
	private List<Object> queue = new ArrayList<Object>();
	private Object readMonitor= new Object ();
	private Object writedMonitor= new Object ();

	public Object getItem() {
		synchronized (readMonitor) {
			if (queue.isEmpty()) {
				try {
					while (queue.isEmpty()) {
						readMonitor.wait();
					}
				} catch (InterruptedException e) {
				}
			}

			if (!queue.isEmpty()) {
				return queue.remove(0);
			} else
				return null;

		}
	}

	public void putItem(Object item) {
		synchronized (readMonitor) {
			queue.add(item);
			queue.notify();
		}
	}

}
